<template>
  <div class="catogory">
    <div class="header">
      <div class="icon"><van-icon name="arrow-left" @click="goback" /></div>
      <div class="search">
        <div class="search_" @click="goSearch">
          <van-icon name="search" class="icon" />
          <span>全场50元起步</span>
        </div>
      </div>
      <p>&nbsp;</p>
    </div>

    <div class="catogory_content">
      <div class="catogory_left">
        <div>
          <ul>
            <li
              v-for="item in list"
              :key="item"
              @click="goCatogory(item.id)"
              :class="{ active: Id == item.id }"
            >
              {{ item.title }}
            </li>
          </ul>
        </div>
      </div>
      <div class="catogory_right">
        <div class="content" v-for="item in page" :key="item">
          <div class="title">{{ item.title }}</div>
          <div class="item" @click="select(20)">
            <div class="item_every" v-for="item in item.list" :key="item">
              <i class="iconfont icon-gouwu icon"></i>
              <div class="name">
                <span>{{ item }}</span>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <Tabbar></Tabbar>
  </div>
</template>

<script>
import List from "../assets/rosurce/resource";
import Tabbar from "../components/Tabbar.vue";
import { toRefs, reactive, onMounted } from "vue";
import { useRouter } from "vue-router";
import { getCategory } from "../service/goods";
import { Toast } from 'vant';
export default {
  components: {
    Tabbar,
  },
  setup() {
    const router = useRouter();
    const state = reactive({
      list: List,
      page: List[0].content,
      Id: 0,
    });
    const goback = () => {
      router.push("/");
    };

    const goSearch = () => {
      router.push("/search");
    };

    onMounted(async () => {
      Toast.loading('加载中')
      const { data } = await getCategory()
      Toast.clear()
      console.log(data);
    })

    const goCatogory = (id) => {
      state.page = List[id].content;
      state.Id = id;
    };

    const select = (id) => {
      console.log(id)
      router.push({path:'/search', query: { categoryId: id }})
    }
    return {
      ...toRefs(state),
      goback,
      goSearch,
      goCatogory,
      select
    };
  },
};
</script>

<style lang="less" scoped>
.header {
  
  display: flex;
  justify-content: space-between;
  padding: 10px;
  font-size: 15px;
  height: 30px;
  align-items: center;
  border-bottom: 1px solid #dcdcdc;
  
}
.header .icon {
  font-size: 18px;
}
.header .search {
  justify-content: center;
  width: 80%;
  height: 90%;
  border-radius: 30px;
  font-size: 12px;
  line-height: 30px;
  color: gray;
  //   border: 1px solid grey;
  background: #f7f7f8;
}
.search_ {
  margin-left: 10px;
  display: flex;
  align-items: center;
}
.search_ .icon {
  font-size: 18px;
  line-height: 25px;
}
.catogory_content {
  display: flex;
}
.catogory_left {
  width: 30%;
  height: calc(100vh - 101px);
  background: #f7f7f8;
}
.catogory_left ul {
  font-size: 15px;
  width: 100%;
}
.catogory_left li {
  float: left;
  text-align: center;
  // margin: 5px;
  // margin: 5px;
  height: 50px;
  line-height: 50px;
  width: 100%;
}
.catogory_right {
  height: 100%;
  overflow-x: hidden;
  overflow-y: scroll;
  width: 70%;
}
.catogory_right .title {
  font-size: 18px;
  margin: 30px 0 20px 10px;
}
.item_every .icon {
  font-size: 30px;
  color: #1baeae;
}

.item {
  display: flex;
  flex-shrink: 0;
  flex-wrap: wrap;
  width: 100%;
  padding-bottom: 13px;
}
.item_every {
  width: 33.3%;
  height: 20%;
  margin-bottom: 10px;
  text-align: center;
}
.name {
  margin-top: 10px;
  font-size: 15px;
}
.active {
  color: #1baeae;
  background: #fff;
}
</style>